package edu.pku.sei.act.ctrl.command;

import org.eclipse.gef.commands.Command;
import edu.pku.sei.act.model.mote.Data;
import edu.pku.sei.act.model.mote.Mote;
import edu.pku.sei.gmp.model.concept.GMPModelElement;

public class CreateDataCommand extends Command{
	private Mote mote;
	private Data data;
	
	public CreateDataCommand(GMPModelElement parent, Data data ) {
		super("Create Data");
		this.mote = (Mote)parent;
		this.data = data;
	}
	
	public boolean canExecute() {
		return mote !=null && data != null ;
	}
	
	public void execute() {
		if (mote != null) {
			data.setContainer(mote);
			mote.setData(data);
		}
	}
	
	public void undo() {
		if (mote != null) {
			mote.setData(null);
		}
		data.setContainer(null);
	}
	
	public void redo(){
		this.execute();
	}
	
}
